<?php
	include("../include/init.php");//将配置文件全部加载进来
	include("../include/check_login.php");//登录

	$insert = new sql_class("article");

	$artcate = new sql_class("article_cate");//查询文章列表
	$artcate_list = $artcate->select()->getAll();


	$article_id = isset($_GET['article_id']) ? $_GET['article_id'] : 0;

	$article_one = $insert->select("article_id = $article_id")->getOne();

	if($_POST){
		$data = array(
					"article_title"=>$_POST['article_title'],
					"article_author"=>$_POST['article_author'],
					"article_time"=>strtotime($_POST['article_time']),
					"article_desc"=>$_POST['article_desc'],
					"article_content"=>$_POST['article_content'],
					"artcate_id"=>$_POST['artcate_id'],
				);
		
		if($_FILES['article_img']['size'] > 0 ){
			$path = DIR."/uploads/";
			$filename = uploads("article_img",1048576,$path);
			$data['article_img'] = "uploads/".$filename;
		}
		$where = "article_id = $article_id";
		$insert_id = $insert->update($data,$where);
		if($insert_id){
			show_msg("更新文章成功","article_list.php");
			exit;
		}else{
			show_msg("更新文章失败","article_edit.php?article_id = $article_id");
			exit;
		}
	}
	
	$smarty->assign("artcate_list",$artcate_list);
	$smarty->assign("article_one",$article_one);
	$smarty->display("admin/article_edit.html");//连接index.html



?>